/*
################################################################################################################################# Included
0 3    B  Allow/prevent teleporting to a landmark : "@tplm=<y/n>"          
1 3    B  Allow/prevent teleporting to a location : "@tploc=<y/n>"  
2 3    B  Allow/prevent teleporting by a friend, secure way : "@tplure_sec=<y/n>"
3 3    B  Unlimit/limit sit-tp : "@sittp=<y/n>"               
4 3    B  Allow/prevent standing up : @unsit=<y/n>     
5 3    B  Allow/prevent sitting down : @sit=<y/n>
6 3    B  Allow/prevent flying : @fly=<y/n> 

#################################################################################################################################
*/
integer attachment = TRUE;
integer relaychannel = -1812221819;
string cmdname;
key victim;
list gMenu=[];
list statesMenu=[0,0,0,0,0,0,0,0];
list gAvatarAllow;
key ToucherID;
integer gMenuLink =1337;
integer gDemon =1338;
integer gPlugin =1339;
integer gVic =1329;
integer channel_dialog;
integer listen_id;
string msg ="Move / TP";
list sideMenu=[" ","Back"," "];

Debug(string _text)
{
	llSay(DEBUG_CHANNEL, _text);
}

llRlvSay(string command)
{
	if(attachment==TRUE)
	{
		llOwnerSay("@"+command);
	}
	else
	{
		llSay(relaychannel,cmdname + "," + (string)victim  + "," + "@"+command);
	}
}

MakeRLVState()
{
	if(attachment==TRUE)
	{
	//onRez we make this to be secure if its an attachmentttt
		if(llList2Integer(statesMenu,0)==1)llRlvSay("tplm=n");
		if(llList2Integer(statesMenu,1)==1)llRlvSay("tploc=n");
		if(llList2Integer(statesMenu,2)==1)llRlvSay("tplure_sec=n");
		if(llList2Integer(statesMenu,3)==1)llRlvSay("sittp=n");
		if(llList2Integer(statesMenu,4)==1)llRlvSay("unsit=n");
		if(llList2Integer(statesMenu,5)==1)llRlvSay("sit=n");
		if(llList2Integer(statesMenu,6)==1)llRlvSay("fly=n");
	}
}

llLRP(integer element_new, integer placeinlist)
{
	statesMenu = llListReplaceList(statesMenu, [element_new], placeinlist, placeinlist);
}

makeMenu()
{
	gMenu=[];
	gMenu+=sideMenu;
	if(llList2Integer(statesMenu,0)==1)gMenu+="[x]TP LM";
	else gMenu+="[ ]TP LM";
	if(llList2Integer(statesMenu,1)==1)gMenu+="[x]TP Location";
	else gMenu+="[ ]TP Location";
	if(llList2Integer(statesMenu,2)==1)gMenu+="[x]TP Friend";
	else gMenu+="[ ]TP Friend";
	if(llList2Integer(statesMenu,3)==1)gMenu+="[x]Far Sit";
	else gMenu+="[ ]Far Sit";
	if(llList2Integer(statesMenu,4)==1)gMenu+="[x]Stand";
	else gMenu+="[ ]Stand";
	if(llList2Integer(statesMenu,5)==1)gMenu+="[x]Sit";
	else gMenu+="[ ]Sit";
	if(llList2Integer(statesMenu,6)==1)gMenu+="[x]Fly";
	else gMenu+="[ ]Fly";
	
	//Than display
	channel_dialog = ( -1 * (integer)("0x"+llGetSubString((string)llGetKey(),-5,-1)) );
	listen_id = llListen( channel_dialog, "", NULL_KEY, "");
	llDialog(ToucherID, msg,gMenu, channel_dialog);
	llSetTimerEvent(45.0);
}

default {
    state_entry() 
    {
    	    
    }
    
    listen(integer channel, string name, key id, string message)
    {
		llListenRemove(listen_id);
		llSetTimerEvent(0.0);
    	if(message=="[x]TP LM"){llLRP(0,0);llRlvSay("tplm=y");makeMenu();}
		if(message=="[ ]TP LM"){llLRP(1,0);llRlvSay("tplm=n");makeMenu();}
		if(message=="[x]TP Location"){llLRP(0,1);llRlvSay("tploc=y");makeMenu();}
		if(message=="[ ]TP Location"){llLRP(1,1);llRlvSay("tploc=n");makeMenu();}
		if(message=="[x]TP Friend"){llLRP(0,2);llRlvSay("tplure_sec=y");makeMenu();}
		if(message=="[ ]TP Friend"){llLRP(1,2);llRlvSay("tplure_sec=n");makeMenu();}
		if(message=="[x]Far Sit"){llLRP(0,3);llRlvSay("sittp=y");makeMenu();}
		if(message=="[ ]Far Sit"){llLRP(1,3);llRlvSay("sittp=n");makeMenu();}
		if(message=="[x]Stand"){llLRP(0,4);llRlvSay("unsit=y");makeMenu();}
		if(message=="[ ]Stand"){llLRP(1,4);llRlvSay("unsit=n");makeMenu();}
		if(message=="[x]Sit"){llLRP(0,5);llRlvSay("sit=y");makeMenu();}
		if(message=="[ ]Sit"){llLRP(1,5);llRlvSay("sit=n");makeMenu();}
		if(message=="[x]Fly"){llLRP(0,6);llRlvSay("fly=y");makeMenu();}
		if(message=="[ ]Fly"){llLRP(1,6);llRlvSay("fly=n");makeMenu();}	
		if(message=="Back")llMessageLinked(LINK_THIS, gMenuLink, "DV_MAIN_RLV", ToucherID);	
		
    }
    
    on_rez(integer on)
    {
    
    }
    
    link_message(integer sender, integer num, string str, key id)
  	{
  		
  		if(num ==gMenuLink)
  		{
  			if(str==llGetScriptName())
  			{
  				llMessageLinked(LINK_THIS, gDemon, llGetScriptName(), NULL_KEY);
  				ToucherID=id;
  				makeMenu();
  			}
  		}
  		if(num ==gDemon)
  		{
  			if(str =="attachment")attachment=TRUE;
  			else if(str =="device")attachment=FALSE;
  			else if(str!=llGetScriptName())
  			{
				llListenRemove(listen_id);
  			}
  		}
  		if(num==gPlugin)
  		{
  			if(str=="ON_REZ")
  			{
  				MakeRLVState();
  			}
  			if(str=="RESET")
  			{
  				statesMenu=[0,0,0,0,0,0,0,0];
  			}
  		}
  		if(num==gVic)
  		{
  				victim=(key)str;
  				cmdname = (string)llGetKey();
  		}
  	}
  	
  	timer()
    {
    	llSetTimerEvent(0.0);
    	llListenRemove(listen_id);
    }
}
